package PHANVANVUONG.XML.DEMO;

import java.io.File;
import java.io.ObjectInputStream.GetField;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

@SuppressWarnings("unused")
public class readFileXml {
	public static void main(String[] args) {
		String url="D:\\Student.xml";
		List<Object> listField=new ArrayList<Object>();
		listField.add("id");
		listField.add("RollNo");
		listField.add("FullName");
		listField.add("Email");
		listField.add("Mark");
		
		CONTROLLERS objC=new CONTROLLERS();
		List<List<HashMap<String, String>>> list=null;
		try {
			list=objC.ReadXMLFiles(listField, "Student", url);
			HashMap<String, String> temp=null;
			for(int i=0; i<list.size(); i++){
				for(int j=0; j<list.get(i).size(); j++){
					temp=list.get(i).get(j);
					System.out.println("ID: "+temp.get("id"));
					System.out.println("RollNo: "+temp.get("RollNo"));
					System.out.println("Full Name: "+temp.get("FullName"));
					System.out.println("Email: "+temp.get("Email"));
					System.out.println("Mark: "+temp.get("Mark"));
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		/*try {
			ClassLoader objcls = Thread.currentThread().getContextClassLoader();
			URL url = objcls.getResource("PHANVANVUONG/XML/DEMO/Student.xml");			
			//System.out.println(f.getPath());
			File fXmlFile = new File(url.toURI());
			DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
			Document doc = dBuilder.parse(fXmlFile);		 
			
			doc.getDocumentElement().normalize();		 
			System.out.println("Root element :" + doc.getDocumentElement().getNodeName());		 
			NodeList nList = doc.getElementsByTagName("Student");		 
			System.out.println("----------------------------");
		    int i = nList.getLength();
		    System.out.println(i);
			for (int temp = 0; temp < nList.getLength(); temp++) {		 
				Node nNode = nList.item(temp);	 
				System.out.println("\nCurrent Element :" + nNode.getNodeName());
		 
				if (nNode.getNodeType() == Node.ELEMENT_NODE) {		 
					Element eElement = (Element) nNode;		 
					System.out.println("ID : " + eElement.getAttribute("id"));
					System.out.println("Roll No : " + eElement.getElementsByTagName("RollNo").item(0).getTextContent());
					System.out.println("Full Name : " + eElement.getElementsByTagName("FullName").item(0).getTextContent());
					System.out.println("Email : " + eElement.getElementsByTagName("Email").item(0).getTextContent());
					System.out.println("Mark : " + eElement.getElementsByTagName("Mark").item(0).getTextContent());
					
				}
			}
		    } catch (Exception e) {
			e.printStackTrace();
		    }			*/
	}
}
